package cn.t.persistence.mapper.device;

import cn.t.model.device.CargowaySkuDO;
import cn.t.persistence.entity.device.CargowaySkuPO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 货道商品表(CargowaySku)领域对象与实体对象转换
 *
 * @author t
 * @since 2024-05-24 10:18:08
 */

public interface CargowaySkuMapper extends BaseMapper<CargowaySkuPO> {

    @Select({"<script> " +
            "SELECT sku_code,sku_name,sku_img,SUM(inventory) as inventory from t_cargoway_sku" +
            " where is_deleted = 'N' AND device_id in " +
            "<foreach item='item' index='index' collection='deviceIds' open='(' separator=', ' close=')'> " + "#{item}" + "</foreach> " +
            " GROUP BY sku_code" +
            "</script>"})
    List<CargowaySkuDO> getGroupBySku(List<Long> deviceIds);

    @Select("SELECT c.cargoway_no, cs.inventory FROM t_cargoway_sku cs " +
            "LEFT JOIN t_cargoway c ON cs.cargoway_id = c.id " +
            "WHERE cs.is_deleted = 'N' AND cs.device_id = #{deviceId} AND cs.sku_code = #{skuCode}")
    List<CargowaySkuDO> getNoAndIntervery(Long deviceId, String skuCode);
}
